package io.gitee.thinkbungee.utils;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author chenyichang
 * @date 2022/3/8
 */
public class Query extends LinkedHashMap<String, Object> {
    /**
     * 当前页码
     */
    private int page;
    /**
     * 每页条数
     */
    private int limit;

    public Query(Map<String, Object> params) {

        params.putIfAbsent("page", 1);
        params.putIfAbsent("limit", 10);

        this.putAll(params);
        this.page = Integer.parseInt(params.get("page").toString());
        this.limit = Integer.parseInt(params.get("limit").toString());

        this.put("offset", (page - 1) * limit);
        this.put("page", page);
        this.put("limit", limit);
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }
}
